const Router = require('koa-router');
const router = new Router();
const tool = require('../../tools/tool')
const {db, QueryTypes} = require("../../models/db");

// 政策兑付
router.post('/pay/zcdflistdetail', async ctx => {
    let user = ctx.user
    let body = ctx.request.body
    let tenantId = user.tenantId;
    let id = body.id
    let excel = body.excel
    let resql = `
        with bills as (
            select a.tenantId,a.invId,b.name invName,b.brandName,
                   a.spec,a.unit,a.sendPrice,sum(a.dz) dz,sum(a.zz) zz,sum(a.cl) cl,sum(a.xl) xl,sum(a.ht) ht,sum(a.ky) ky,sum(a.zy) zy,sum(a.qty) qty
            from send_df_detail a inner join v_goods b on a.tenantId=b.tenantId and a.invId=b.id
            where sendDfId=${id} and a.tenantId=${tenantId} 
            GROUP BY a.tenantId, a.invId, b.name, b.brandName, a.spec, a.unit, a.sendPrice
        ) select tenantId, invId, invName, brandName, spec, unit, sendPrice,
                 dz/spec dz, zz/spec zz, cl/spec cl, xl/spec xl, ht/spec ht, ky/spec ky, zy/spec zy, qty/spec qty, (qty/spec)*sendPrice amount from bills
        order by invName
    `
    let res = await db.query(resql, {type: QueryTypes.SELECT})
    return ctx.suc('', {
        list: res
    })

})



module.exports = router;
